I found 5 things that didn't work as expected today when porting p5 code to p6. I really think this is a great way to improve your p6 skills as well as find subtle bugs
1. my %hash = map { $_ => $_ } @array;
That correctly doesn't work. It was just unexpected. Either of the following two does work (as designed):
my %hash = map { $_ => $_; } @array;
my %hash = map -> $_ { $_ => $_ } @array;
2. sub foo (Int $bar) {say $bar;} foo('hello')
I was hoping for a type check error. Instead it just says "hello\n". While this is a bug, it is unclear what the proper behavior should be. My recollection that the difference between int and Int is that 1 would autocovert for you but wouldn't remember doing it while the other would be an outright failure. Autrijus has encouraged me to write p6.l about it so the proper behavior can have a test added (which I will do).
3. 0 .. $foo - 3 didn't work as expected. I needed to do 0 .. ($foo - 3). This apparently was a bug introduce with infix operators that had already been fixed. Regardless it should have a test for it to make sure it doesn't get unfixed. I believe iblech volunteered for the job.
4. my $i=3; my @array = 1..5; @array[ --$i ]++; say $i
That printed 1 and not 2. This apparently has already been fixed as well but should have a "make sure it doesn't break again" test.
5. while ( my @combo = sort { $^a <=> $^b } ) { ... }
This doesn't work. Autrijus agrees that it is a bug but wants a minimal test case. I am going to try and provide it.
For challenge and more information, see
The colon turns it into an adverbial block to map.# |
# V
my %hash = map:{ $_ => $_ } @array;
Re:Map adverb
kelan on 2005-05-19T23:50:56
Scratch that. Looks like adverbial blocks can't be in the middle of an argument list, so it would be:my %hash = @array.map:{ $_ => $_ };